package com.hzxy.yiyid.web.module.controller;

import com.hzxy.yiyid.web.common.base.BaseResult;
import com.hzxy.yiyid.web.common.error.ErrorCodeEnum;
import com.hzxy.yiyid.web.module.controller.Dto.FoodRechange;
import com.hzxy.yiyid.web.module.controller.Dto.FoodRecommendDto;
import com.hzxy.yiyid.web.module.service.FoodTypeService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/food")
public class FoodTypeController {

    private static final Logger logger = LoggerFactory.getLogger(AtricleController.class);

    @Autowired
    private FoodTypeService foodTypeService;

//    @PostMapping("/foodRechange")
//    @ApiOperation(value ="通过食物类型返回所有符合该类型的" ,notes = "通过食物类型返回所有符合该类型的" )
//    public BaseResult<?> foodRechange(@RequestBody FoodRechange foodRechange){
//        if(StringUtils.isBlank(foodRechange.getFoodtype())){
//            logger.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(),ErrorCodeEnum.DOCTOR_PARAM_NULL_ERROR.getMsg());
//            return BaseResult.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(),ErrorCodeEnum.DOCTOR_PARAM_NULL_ERROR.getMsg());
//        }
//        return foodTypeService.foodRechange(foodRechange.getFoodtype());
//    }

    @GetMapping("/{foodTypeId}")
    @ApiOperation(value ="通过食物类型返回所有符合该类型的" ,notes = "通过食物类型返回所有符合该类型的" )
    public BaseResult<?> foodRechange(@PathVariable("foodTypeId") Integer foodTypeId){
        if(StringUtils.isBlank(foodTypeId.toString())){
            logger.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(),ErrorCodeEnum.DOCTOR_PARAM_NULL_ERROR.getMsg());
            return BaseResult.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(),ErrorCodeEnum.DOCTOR_PARAM_NULL_ERROR.getMsg());
        }
        return foodTypeService.foodRechange(foodTypeId);
    }
    @PostMapping("/foodRechange/btnid")
    @ApiOperation(value ="通过前端传进来的按钮值进行推荐食物" ,notes = "通过前端传进来的按钮值进行推荐食物" )
    public BaseResult<?> foodRechangeById(@RequestBody  FoodRecommendDto foodRecommendDto){
        if(StringUtils.isBlank(foodRecommendDto.getFoodTypeId().toString()) && StringUtils.isBlank(foodRecommendDto.getBtnid().toString())){
            logger.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(),ErrorCodeEnum.DOCTOR_PARAM_NULL_ERROR.getMsg());
            return BaseResult.error(ErrorCodeEnum.REQUEST_PARAM_NULL_ERROR.getErrorCode(),ErrorCodeEnum.DOCTOR_PARAM_NULL_ERROR.getMsg());
        }
        return foodTypeService.foodRechangeById(foodRecommendDto.getBtnid(),foodRecommendDto.getFoodTypeId());
    }
}
